package edu.learn.config;

import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

@Configuration
public class MybatisConfig {

    //构建SqlSessionFactory
    @Bean
    public SqlSessionFactoryBean sqlSessionFactoryBean( DataSource dataSource){
        SqlSessionFactoryBean ssfb = new SqlSessionFactoryBean();
        //xml中方便entity类型命名
        ssfb.setTypeAliasesPackage("edu.learn.entity");
        //拿到之前造的druid datasource
        ssfb.setDataSource(dataSource);
        return ssfb;
    }

    @Bean
    public MapperScannerConfigurer mapperScannerConfigure(){
        MapperScannerConfigurer msc = new MapperScannerConfigurer();
        msc.setBasePackage("edu.learn.mapper");
        return msc;
    }
    
}
